//
//  shenheshoucangViewController.m
//  movie
//
//  Created by 白浩洋 on 2018/4/24.
//  Copyright © 2018年 白浩洋. All rights reserved.
//

#import "shenheshoucangViewController.h"
#import "zixunViewController.h"
@interface shenheshoucangViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *dataSource;
@property (nonatomic,strong)UITableView *tabView;

@end

@implementation shenheshoucangViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addCustomTitleWithTitle:@"我的收藏"];
    [self.tabView.mj_header beginRefreshing];
}
-(NSMutableArray *)dataSource{
    if(!_dataSource){
        _dataSource = [[NSMutableArray alloc]initWithArray:[NBATools getshenheshoucang]];
    }
    return _dataSource;
}
- (UITableView *)tabView{
    if(!_tabView){
        _tabView = [[UITableView alloc]initWithFrame:CGRectMake(0,PXChange(20), ScreenWidth, self.view.height - PXChange(20) -iPhoneXTabHeigth - 64)];
        _tabView.delegate = self;
        _tabView.dataSource =self;
        _tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tabView];
    }
    return _tabView;
}
#pragma mark - tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return PXChange(200);
}
#pragma mark - tableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    [cell.contentView removeAllSubviews];
    NSDictionary *dic = self.dataSource[indexPath.row];
    NSDictionary *datadic = dic[@"dic"];
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, PXChange(240), PXChange(160))];
    [image sd_setImageWithURL:[NSURL URLWithString:datadic[@"banner"]] placeholderImage:[UIImage imageNamed:@"jpghold"]];
    image.center = CGPointMake(PXChange(10) + image.width/2.0f, PXChange(100));
    [cell.contentView addSubview:image];
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth - PXChange(300), 0)];
    lab.text = datadic[@"title"];
    lab.textColor = [UIColor colorWithHexString:@"#333333"];
    lab.font = [UIFont systemFontOfSize:PXChange(28)];
    lab.numberOfLines = 0;
    [lab sizeToFit];
    lab.center = CGPointMake(image.right + PXChange(20) + lab.width/2.0f, PXChange(100));
    [cell.contentView addSubview:lab];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = self.dataSource[indexPath.row];
    NSString *url = dic[@"url"];
    zixunViewController *zvc= [[zixunViewController alloc]init];
    zvc.url = url;
    zvc.dic = dic;
    zvc.type = 100;
    zvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:zvc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
